<?php
namespace app\common\validate;
use think\Validate;
class ShopProduct extends Validate
{
    protected $rule    = [
        'shop_id' => 'require',
        'title' => 'require',
        'market_price' => 'require|float',
        'price' => 'require|float',
        'zhe' => 'require|float',
        'nums' => 'require|integer',
        'youhui_type' => 'require',
        'type' => 'require',
        'type_times' => 'require',
        'end_time' => 'require|integer|length:10|checkTime',
    ];
    protected $message = [
        'title.require' => '商品名称不能为空',
        'market_price.require' => '请输入原价',
        'market_price.float' => '原价格式不对',
        'price.require' => '请输入价格',
        'price.float' => '价格格式不对',
        'nums.require' => '请输入份数',
        'nums.integer' => '份数格式不对',
        'youhui_type.require' => '请选择优惠人群',
        'type.require' => '请选择使用周期',
        'type_times.require' => '请选择次数',
        'end_time.require' => '截止日期不能为空',
        'end_time.integer' => '截止日期必须为整数',
        'end_time.length' => '截止日期长度错误',
    ];
    //验证截止日期
    protected function checkTime($value)
    {
        $temp = $value-7*24*60*60;
        return $temp<time() ? '截止日期至少为7天' : true;
    }
}
